<template>
	<view class="dfj-pd-t-50">
		<uni-nav-bar :fixed="true" left-icon="back" title="登录" @clickLeft="leftBack" background-color="#318cff" color="#fff"></uni-nav-bar>
		<view class="dfj-pd-t-50 dfj-t-c">
			<image src="/static/img/login.png" style="width: 150rpx;height: auto;border-radius: 100%;" mode="widthFix"></image>
		</view>
		<view class="dfj-f-35 dfj-t-333 dfj-t-c dfj-pd-tb-15">欢迎您</view>
		<view class="dfj-pd-lr-30 dfj-pd-tb-50">
			<view>
				<input class="dfj-bd-b-e1e dfj-pd-tb-20" v-model="form.mobilePhone" maxlength="11" type="number" placeholder="请输入手机号码"/>
			</view>
			<view class="dfj-flex dfj-flex-ai-c dfj-mg-t-20">
				<view class="dfj-flex-1">
					<input type="password" class="dfj-bd-b-e1e dfj-pd-tb-20 dfj-mg-r-30" v-model="form.userPwd" placeholder="请输入密码"/>
				</view>
				<view>
					<navigator url="/pages/user/forget-password" class="dfj-t-666">忘记密码?</navigator>
				</view>
			</view>
			
			
			<view class="dfj-mg-t-50"><button type="primary" @click="login()">登录</button></view>
			<view class="dfj-mg-t-30">
				<navigator url="/pages/user/register">
					<button>注册</button>
				</navigator>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					mobilePhone:'',//18688888888
					userPwd:'',//aa888888
					cid:''
				}
			}
		},
		onLoad() {
			localStorage.removeItem('loginInfo')
			localStorage.removeItem('search')
		},
		methods:{
			leftBack() {
				uni.switchTab({
					url: '/pages/home/home'
				})
			},
			login() {
				if(!(/^1[3456789]\d{9}$/.test(this.form.mobilePhone))){
				    uni.showToast({
				    	title:'手机号有误',
						icon: 'none'
				    })
				    return false; 
				}
				if(this.form.userPwd==''){
					uni.showToast({
						title:'请输入密码',
						icon: 'none'
					})
					return false; 
				}
				this.$http({
					url: '/sys/login',
					data: this.form
				}).then(res=>{
					if(res.flag){
						localStorage.setItem('loginInfo',JSON.stringify(res.data))
						uni.showToast({
							title:'登录成功'
						})
						uni.switchTab({
							url:'/pages/home/home'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{background: #fff;}
</style>
